package ast.grammar;

import org.antlr.runtime.ANTLRStringStream;
import org.antlr.runtime.CharStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.TokenStream;
import org.antlr.runtime.tree.CommonTree;
import org.antlr.runtime.tree.CommonTreeNodeStream;

import ast.gen.EvaluatorWalker;
import ast.gen.SampleASTLexer;
import ast.gen.SampleASTParser;
import ast.gen.SampleASTParser.evaluator_return;
import ast.gen.VisEvaluatorWalker;

public class TestAST {

	public static void main(String[] args) throws RecognitionException {
		CharStream charStream = new ANTLRStringStream("x:=3;2+4-x");
		SampleASTLexer lexer = new SampleASTLexer(charStream);
		TokenStream tockenStream = new CommonTokenStream(lexer);
		SampleASTParser parser = new SampleASTParser(tockenStream);
		evaluator_return evaluator = parser.evaluator();
		System.out.println(((CommonTree) (evaluator.getTree())).toStringTree());
		CommonTreeNodeStream stream = new CommonTreeNodeStream(
				evaluator.getTree());
		EvaluatorWalker walker = new EvaluatorWalker(stream);
		int result = walker.evaluator();
		System.out.println("ok " + result);

		CommonTreeNodeStream stream2 = new CommonTreeNodeStream(
				evaluator.getTree());
		VisEvaluatorWalker walker2 = new VisEvaluatorWalker(stream2);
		System.out.println(walker2.evaluator());
	}
}
